<template>
  <div class="search">
    <div class="search_kuang">
      <input type="text" v-model="searchContent" name="" placeholder="输入搜索内容">
      <button @click="searchSong" name="button" type="button">搜索</button>
    </div>
    <ul>
      <router-link tag="li" :to="{name:'musicplay',params:{songid:item.songid}}" :key="index" v-for="(item,index) in searchData">
        {{ item.songname }}-{{ item.artistname }}
      </router-link>
    </ul>
  </div>
</template>

<script>
  export default {
    name:'search',
    data(){
      return{
        searchContent:'',
        searchData:[]
      }
    },
    methods:{
      searchSong(){
        let url = this.HOST + '/v1/restserver/ting?method=baidu.ting.search.catalogSug&query=' + this.searchContent
        this.$axios.get(url)
          .then(res => {
            if(res.data.error_code == 22001){
              this.$message('搜索数据不存在');
              alert("no")
              return;
            }
            this.searchData = res.data.song
          })
          .catch(error => {
            console.log(error)
          })
      }
    }
  }
</script>

<style scoped>
.search_kuang{
  padding: 20px;
  overflow: hidden;
  clear: both;
}
input{
  width: 80%;
  height: 30px;
  line-height: 30px;
  background: #fff;
  border:1px solid #f1f2f3;
  padding-left: 10px;
  float: left;
  display: inline-block
}

button{
  float: left;
  width: 15%;
  height: 32px;
}

ul{
  width: 100%;
  height: 100%;
  margin-top: 5px
}

ul li{
  width: 90%;
  margin: 0 auto;
  list-style: none;
  height: 40px;
  line-height: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>